package com.example.jeong.yuejian10.Model;


import com.example.jeong.yuejian10.Bean.ActivityBean;
import com.example.jeong.yuejian10.Bean.AttentionBean;
import com.example.jeong.yuejian10.Bean.EnterActBean;
import com.example.jeong.yuejian10.Bean.IsAttentionBean;
import com.example.jeong.yuejian10.Listener.RetrofitListener;
import com.example.jeong.yuejian10.Service.ActivityService;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

import static com.example.jeong.yuejian10.constant.Constant.BASE_URL;


public class ActivityModel {
    private Retrofit retrofit;
    public ActivityModel(){
        //创建实例
        retrofit = new Retrofit.Builder()
                .baseUrl(BASE_URL)
                .addConverterFactory(GsonConverterFactory.create())
                .build();

    }
    //活动列表
    public void activitylist(final RetrofitListener listener){
        ActivityService activityService = retrofit.create(ActivityService.class);
        Call call = activityService.getActivitylist();
        Callback<List<ActivityBean>> callback = new Callback<List<ActivityBean>>() {
            @Override
            public void onResponse(Call<List<ActivityBean>> call, Response<List<ActivityBean>> response) {
                List<ActivityBean> trainBeen = response.body();
                listener.onSuccess(trainBeen);
            }
            @Override
            public void onFailure(Call<List<ActivityBean>> call, Throwable t) {
                listener.onFail();
            }
        };
        call.enqueue(callback);

    }




    //活动详情
    public  Call<ActivityBean> activityDetail(int a_id){
        ActivityService postService = retrofit.create(ActivityService.class);
        return postService.getDetail(a_id);
    }

    //活动列表
    public Call<List<ActivityBean>> getActivitylist(){
        ActivityService activityService = retrofit.create(ActivityService.class);
        return activityService.getActivitylist();
    }
    //活动详情
    public Call<ActivityBean> getDetail(int a_id){
        ActivityService activityService = retrofit.create(ActivityService.class);
        return activityService.getDetail(a_id);
    }





    //报名活动
    public Call<EnterActBean> addactivityn(int u_id, int a_id){
        ActivityService activityService = retrofit.create(ActivityService.class);
        return activityService.addactivityn(u_id,a_id);
    }

    //判断是否关注
    public Call<IsAttentionBean> getIsCollected(int u_id, int select_id, String flag){
        ActivityService activityService=retrofit.create(ActivityService.class);
        return activityService.getIsCollected(u_id, select_id, flag);
    }

    //关注活动
    public Call<AttentionBean> userCollectActivity(int u_id, int a_id){
        ActivityService activityService=retrofit.create(ActivityService.class);
        return activityService.userCollectActivity(u_id,a_id);
    }

}